﻿<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="author" content="m.ecdrt.com">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" name="viewport" />
    <meta name="format-detection" content="telephone=no" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <meta content="false" id="twcClient" name="twcClient" />
    <link type="text/css" rel="stylesheet" href="/shop/templates/cdrt/css/style_1.css">
    <link rel="apple-touch-icon-precomposed" href="{$shopconfig.logo}" />
    <link rel="shortcut icon" type="image/x-icon" href="{$shopconfig.logo}" />
    <link type="text/css" rel="stylesheet" href="/shop/templates/cdrt/css/member.css">
    <link rel="stylesheet" href="../../../Content/weui/weui.min.css" />
    <link rel="stylesheet" href="../../../Content/weui/weui.example.css" />
    <style type="text/css">
        #bg {
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100%;
            height: 100%;
            background-color: black;
            z-index: 1001;
            -moz-opacity: 0.1;
            opacity: .10;
            filter: alpha(opacity=70);
        }
        #show {
            display: none;
            position: absolute;
            top: 25%;
            left: 25%;
            width: 50%;
            height: 50%;
            padding: 8px;
            z-index: 1002;
        }
        .imgtoast {
            position:absolute;
            width:50%;
            left:25%;
            top:25%;
        }
    </style>

    <script type="text/javascript" src="/shop/templates/cdrt/js/zepto.js"></script>
    <script type="text/javascript" src="/shop/templates/cdrt/js/mediav.js"></script>
    <script type="text/javascript" src="/shop/templates/cdrt/js/touch.js"></script>
    <script src="/scripts/jquery/jquery-2.1.0.min.js"></script>
    <script src="/scripts/jquery/jquery.query.js"></script>
    <script type="text/javascript">
    $(function () {
      //统计购物车数量
      $.getJSON("/shop/shopmgr.ashx?wid={$wid}&openid={$openid}&myact=pcount&ss=" + Math.random(), function (d, status) {
        $("#count").text(d.data);
        if (d.data <= 0) {
          $("#by").hide();
          $("#buy").hide();
        } else {
          $("#by").show();
          $("#buy").show();
          $("#bu").hide();
        }
      });
    });

    $(document).ready(function () {
        var wid = $.query.get("wid");
        var rtn = $.query.get("rtn");
        var openid = $.query.get("openid");
        var rtnurl;
        if (rtn == 'shop') {
            rtnurl = "/shop/index.aspx?wid=" + wid + "&openid=" + openid;
        }
        else
        {
            rtnurl = "/shop/reward_index.aspx?wid=" + wid + "&openid=" + openid;
        }

        $('.fh >a').attr('href', rtnurl);
        $('.Login > a').attr('href', rtnurl);
        $('.footer a:eq(1)').attr('href', rtnurl);
    })

    </script>
</head>
<body id="page">
    <header class="header">
        <span class="fh left"><a href="{$indexurl}">&nbsp;</a></span>
        购物车
        <span class="hd_right right">
            <a class="gwc" href="{$carturl}"><span id="count"></span>&nbsp;</a>
            <a class="right_but" href="/shop/navigate.aspx?wid={$wid}&openid={$openid}">&nbsp;</a>
        </span>
    </header>
    <div class="Login buy_null" id="bu">
        <div class="buy_car">
            <img src="/shop/templates/cdrt/images/buycar_icon.png" style="width: 50%;" />
        </div>
        <p>购物车还是空的，现在开始行动吧！</p>
        <a href="{$indexurl}" class="address_addbutton">去首页看看</a>
    </div>

    <vt:foreach from="$cartlist" item="cproduct" index="i">
        <div class="list_msg list_with_img" style="margin-top:10px;" id="by">
            <a href="{$cproduct.productUrl}"><img src="{$cproduct.productPic}"></a>
            <ul>
                <li>{$cproduct.productName} {$cproduct.skuInfo}</li>
                <li>购买价格：<span class="txt_red">￥{$cproduct.avgPrice}元</span> &nbsp;&nbsp;&nbsp;库存数量：<span class="txt_red">{$cproduct.stock}</span></li>
                <li>
                    购买数量：
                    <span class="count_num" id="{$cproduct.id}" pid="{$cproduct.productid}" skuid="{$cproduct.skuid}">
                        <a href="javascript:;" name="count-min" class="inputcheckbox">-</a>
                        <div class="count-input">
                            <input type="text" maxlength="2" value="{$cproduct.productNum}" id="proCount{$cproduct.id}" readonly />
                        </div>
                        <a href="javascript:;" name="count-add" class="inputcheckbox">+</a>
                    </span>
                    <a name="remove" href="javascript:;" pid="{$cproduct.id}" class="m-btn btn-red" style="height:26px; line-height:26px; font-size:14px;">删除</a>
                </li>
            </ul>
        </div>
    </vt:foreach>
    <vt:foreach from="$jfcartlist" item="cproduct" index="i">
        <div class="list_msg list_with_img" style="margin-top:10px;" id="by">
            <a href="{$cproduct.productUrl}"><img src="{$cproduct.productPic}"></a>
            <ul>
                <li>{$cproduct.productName}[{$cproduct.skuInfo}]</li>
                <li>兑换价格：<span class="txt_red">{$cproduct.avgPrice}积分</span>&nbsp;&nbsp;&nbsp;库存数量：<span class="txt_red">{$cproduct.stock}</span></li>
                <li>
                    兑换数量：
                    <span class="count_num" id="{$cproduct.id}"  pid="{$cproduct.productid}" skuid="{$cproduct.skuid}">
                        <a href="javascript:;" name="count-min" class="inputcheckbox">-</a>
                        <div class="count-input">
                            <input type="text" maxlength="2" value="{$cproduct.productNum}" id="proCount{$cproduct.id}" readonly />
                        </div>
                        <a href="javascript:;" name="count-add" class="inputcheckbox">+</a>
                    </span>
                    <a name="remove" href="javascript:;" pid="{$cproduct.id}" class="m-btn btn-red" style="height:26px; line-height:26px; font-size:14px;">删除</a>
                </li>
            </ul>
        </div>
    </vt:foreach>
    <div class="buy_js address_button" id="buy">
        <p>总积分：<span id="finalPrice">{$userscore}</span></p>
        <p>订单总计：￥<span id="finalPrice">{$alltot}</span>&nbsp&nbsp 积分：<span id="finalPrice">{$alltosocre}</span></p>
        <a id="settlement" class="submit">去结算</a>
        <div id="bg"></div>
        <div id="show"><img class="imgtoast" src="/images/loading1.gif" /></div>

            
        </div>
    <vt:template id="_bottom" file="_bottom.html" charset="utf-8" />
    <div class="tc2" style="display: none;">
        <div class="kf_top">
            <p class="dh">4008-281-919</p>
            <p class="tc_cg">早8:00 - 晚20:00</p>
        </div>
        <div class="tc_button">
            <ul>
                <li><a href="tel:4008-281-919">拨打咨询</a></li>
                <li><a href="javascript:void(0)" class="lxkf_close">取消</a></li>
            </ul>
        </div>
    </div>

    <script type="text/javascript">
       

        var allright = true;
        var results;
        $("#settlement").click(function () {
            document.getElementById("bg").style.display = "block";
            document.getElementById("show").style.display = "block";
            var length = $("input[type='text']").length;
            results = new Array(length);
            for (var i = 0; i < length; i++)
            {
                results[i] = false;
            }
            $("input[type='text']").each(function (i) {
               
                var $productId = $(this).parent().parent();
                var id = $productId.attr('id');
                var pid = $productId.attr('pid');
                var skuid = $productId.attr('skuid');
                var valu = parseInt($(this).attr('value'));
                var inputn = $(this);
                $.getJSON("/shop/shop.ashx?wid={$wid}&id=" + pid + "&skuid=" + skuid + "&myact=checkid", function (d, status) {
                    if (typeof (d.data) == "undefined") {
                        alert('购买出现问题，请联系管理员。');
                    }
                    else if (d.data >= valu) {
                        results[i] = true;
                    }
                    else if (d.data < valu) {
                        results[i] = true;
                        allright = false;
                        modifycart_(id, d.data, false);
                        inputn.val(d.data);

                    }
                });

            }
            
            );
            setTimeout('buy()', 100);
          //href = "/shop/confirmOrder.aspx?wid={$wid}&openid={$openid}"
        })

        function buy()
        {
            for (var i = 0; i < results.length; i++)
            {
                if (results[i] == false)
                {
                    alert(i);
                    setTimeout('buy()', 100);
                    return;
                }
            }
            document.getElementById("bg").style.display = "none";
            document.getElementById("show").style.display = "none";
            if (allright) {
                window.location.href = "/shop/confirmOrder.aspx?wid={$wid}&openid={$openid}";
            }
            else {
                alert('由于购物车数量超过了库存，需要重新确认订单，对您造成的不便请见谅。');
                window.location.href = "{$carturl}";
            }
        }
            
        function showtoast() {
           
        }

        function modifycart_(id, count, refresh) {
            $.ajax({
                type: 'POST',
                url: '/shop/shopmgr.ashx?myact=modifyNum',
                data: { ic: id, bc: count },
                success: function (data) {
                    if (refresh) {
                        window.location.href = "{$carturl}";
                    }
                },
                error: function (data) {
                    alert("操作失败，请刷新页面后重新尝试");
                },
                dataType: 'json'
            });
        }

    $(".lxkf").click(function () {
      if ($('#load_mask').length) { }
      else {
        var h = $(document.body).height() + "px";
        $("<div id='load_mask' class='tc_zz' style='height:" + h + "' />").appendTo("body");
      }
      $("#load_mask").show();
      var t = $(window).scrollTop(), h = $(window).height(), iTop = 0;
      iTop = ((h - $(".tc2").height()) / 2 + t) + "px";
      $(".tc2").css("top", iTop).show();
    })

    $(".lxkf_close").click(function () {
      $(".tc2").hide();
      $("#load_mask").hide();
    })
    </script>
    <script type="text/javascript" src="/shop/templates/cdrt/js/util.js"></script>
    <script type="text/javascript">
    $(function ($) {
      $("a[name='remove']").click(function () {
          var productId = $(this).attr("pid");
          var rtn = $.query.get("rtn");
        ($).get("/shop/shopmgr.ashx?myact=remove", { "id": productId }, function (d) {
          if (d.errCode == "false") {
            location.href = "{$carturl}"+"&rtn="+rtn;
          }
          if (typeof (d.errCode) == "undefined") {
              location.href = "{$carturl}" + "&rtn=" + rtn;
          }
        });
      });

      function modifycart(id, count, refresh)
      {
          $.ajax({
              type: 'POST',
              url: '/shop/shopmgr.ashx?myact=modifyNum',
              data: { ic: id, bc: count },
              success: function (data) {
                  if(refresh){
                      window.location.href = "{$carturl}";
                  }
              },
              error: function (data) {
                  alert("操作失败，请刷新页面后重新尝试");
              },
              dataType: 'json'
          });
      }

      $("a[name='count-add']").click(function () {
          var $productId = $(this).parent();
          var id = $productId.attr('id');
          var pid = $productId.attr('pid');
          var skuid = $productId.attr('skuid');
          var $input = $("#proCount" + id);
          var valu = $input.attr('value');
          var a = ++valu;
          $.getJSON("/shop/shop.ashx?wid={$wid}&id=" + pid + "&skuid="+skuid+"&myact=checkid", function (d, status) {
              if (typeof (d.data) == "undefined") {
                  alert('购买出现问题，请联系管理员。');
              }
              else if (d.data >= a) {
                  modifycart(id, a , true);
              }
              else if (d.data < a) {
                  alert('抱歉，所选商品库存不足。');
                  $input.attr("value", d.data);
                  modifycart(id, d.data, true)
                  
              }
          });
      });

      $("a[name='count-min']").click(function () {
          var $productId = $(this).parent();
          var id = $productId.attr('id');
          var pid = $productId.attr('pid');
          var skuid = $productId.attr('skuid');
          var $input = $("#proCount" + id);
          var valu = $input.attr('value');
        var a = --valu;
        if (a > 0) {
            $.getJSON("/shop/shop.ashx?wid={$wid}&id=" + pid + "&skuid="+skuid+"&myact=checkid", function (d, status) {
                if (typeof (d.data) == "undefined") {
                    alert('购买出现问题，请联系管理员。');
                }
                else if (d.data >= a) {
                    modifycart(id, a, $input);
                }
                else if (d.data < a) {
                    alert('抱歉，所选商品库存不足。');
                    $input.attr("value", d.data);
                    modifycart(id, d.data, input)
                    
                }
            });
        }
        else {
              $input.attr("value", 1);
              alert("购买数量不能小于1");
        }
      });
    });
    </script>
</body>
</html>